package com.hbx.platform.auth.service.impl;

import com.hbx.platform.auth.domain.Permission;
import com.hbx.platform.auth.mapper.PermissionMapper;
import com.hbx.platform.auth.service.IPermissionService;
import com.hbx.platform.base.service.impl.BaseServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author hbx
 * @since 2024-04-06
 */
@Service
public class PermissionServiceImpl extends BaseServiceImpl<Permission> implements IPermissionService {

    @Autowired
    private PermissionMapper permissionMapper;

    @Override
    public void save(Permission permission) {
        if(permission.getParent() != null){
            permission.setParentId(permission.getParent().getId());
        }
        super.save(permission);
    }

    @Override
    public void update(Permission permission) {
        if(permission.getParent() != null){
            permission.setParentId(permission.getParent().getId());
        }
        super.update(permission);
    }

    public Permission queryBySn(String sn) {
        return permissionMapper.queryBySn(sn);
    }

    @Override
    public List<Permission> getTree() {
        return permissionMapper.getTree();
    }

    @Override
    public List<String> getPermissionsByEmpId(Long id) {
        return permissionMapper.getPermissionsByEmpId(id);
    }
}
